<template>
    <div>
      <Row>
        <Col span="6">
          <Table border :columns="columns" :data="data" :loading="tableLoading"></Table>
        </Col>
        <Col span="18">
          <div ref="echartPie" style="width: 1400px;height: 600px;text-align: center">
          </div></Col>
      </Row>
    </div>
</template>

<script>
import { findbdNumList, dycgetSomeNum } from '../../../../api/eventlist'
import echarts from 'echarts'

export default {
  name: 'comparison-tab',
  data () {
    return {
      columns: [
        {
          title: '事项编号',
          key: 'item_id',
          align: 'center'
        },
        {
          title: '事项名称',
          key: 'title',
          align: 'center'
        },
        {
          title: '比对次数',
          key: 'num',
          align: 'center'
        }
      ],
      data: [],
      tableLoading: false,
      titleList: [],
      numList: []
    }
  },
  methods: {
    init () {
      // this.setOpotionPie()
      findbdNumList().then(ret => {
        if (ret.data.errcode === 0) {
          let result1 = ret.data.data
          dycgetSomeNum().then(ret => {
            if (ret.data.errcode === 0) {
              let result2 = ret.data.data
              result1.forEach(item1 => {
                result2.forEach(item2 => {
                  if (item1.item_id === item2.item_id) {
                    item1.num = item2.num6
                  }
                })
              })
              this.data = result1
              this.data.forEach(item => {
                this.titleList.push(item.title)
                this.numList.push(item.num)
              })
              let count = 0
              this.data.forEach(item3 => {
                count = count + item3.num
              })
              this.data.push({
                item_id: '合计',
                title: '',
                num: count
              })
              this.$nextTick(() => {
                this.setOpotionPie()
              })
            } else {
              this.$Notice.error({ title: '获取信息失败', desc: ret.data.errmsg })
            }
          })
        } else {
          this.$Notice.error({ title: '获取信息失败', desc: ret.data.errmsg })
        }
      })
    },
    getSomeNum () {

    },
    setOpotionPie () {
      let tempDom = echarts.init(this.$refs.echartPie)
      let option = {
        yAxis: {
          type: 'category',
          data: this.titleList
        },
        // tooltip: {
        //   trigger: 'axis',
        //   axisPointer: {
        //     type: 'shadow'
        //   }
        // },
        tooltip: {
          trigger: 'item',
          formatter: '{b} : {c}'
        },
        grid: {
          left: '28%'
        },
        xAxis: {
          type: 'log'
        },
        series: [{
          data: this.numList,
          type: 'bar'
        }]
      }
      tempDom.setOption(option)
    }

  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped>

</style>
